package com.zzq.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

@ApiModel("返回类")
@Data
@Accessors(chain = true)
public class IResult<T> {
    @ApiModelProperty("状态码(100执行成功, 200执行失败)")
    private int code;
    @ApiModelProperty("提示信息")
    private String msg;
    @ApiModelProperty("主要数据")
    private T data;
    @ApiModelProperty("额外数据")
    private Map<String, Object> map = new HashMap<>();

    public static IResult success() {
        IResult result = new IResult();
        result.setCode(100);
        result.setMsg("处理成功！");
        return result;
    }

    public static IResult success(String msg) {
        IResult result = new IResult();
        result.setCode(100);
        result.setMsg(msg);
        return result;
    }

    public static IResult success(String msg, Object obj) {
        IResult result = new IResult();
        result.setCode(100);
        result.setMsg(msg);
        result.setData(obj);
        return result;
    }

    public static IResult success(Object obj) {
        IResult result = new IResult();
        result.setCode(100);
        result.setMsg("处理成功！");
        result.setData(obj);
        return result;
    }

    public static IResult success(Object obj, String token) {
        IResult result = new IResult();
        result.setCode(100);
        result.setMsg("处理成功！");
        result.setData(obj);
        result.getMap().put("token", token);
        return result;
    }

    public static IResult error() {
        IResult result = new IResult();
        result.setCode(200);
        result.setMsg("处理失败！");
        return result;
    }

    public static IResult error(String msg) {
        IResult result = new IResult();
        result.setCode(200);
        result.setMsg(msg);
        return result;
    }
}